<template>
	<view class="center">
		<image class="bg-set" src="../../static/global-bg.jpg" mode="widthFix"></image>
		<view class="center_top">
			<view class="mask"></view>
		</view>
		<view class="center_box_bg">
			<view class="profily">
				<view class="base">
					<view class="profily_header"></view>
					<text>{{timeStr}}好！{{userInfo.username}}</text>
					<text @click="exit" class="cuIcon-exit setting-icon"></text>
				</view>
				<view class="order_todos">
					<view class="todos" v-for="(item,indx) in todos" :key="item.key" @click.stop="handleTodoClick(item.key)">
							<view class="todos_icons" :class="item.className"></view>
							<text>{{item.name}}</text>
					</view>
				</view>
			</view>
			<view class="baiban">
			</view>
			<view class="center_menu">
				<view class="menu_item" v-for="(item,index) in menus" :key="index"  @click="handleMenuClick(item.key)">
						<view class="menu_icons" :class="item.className"></view>
						<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<dialog-modal
			:dialogVisible="dialogVisible"
			title="提示" 
			content="你确定要退出登录吗？" 
			@handleCancel="handleCancel" 
			@handleSure="handleSure"
		></dialog-modal>
	</view>
</template>

<script>
	import { mapState, mapMutations } from 'vuex'
	import DialogModal from '@/components/DialogModal.vue'
	export default {
		components: {
			DialogModal
		},
		mounted() {
			console.log(this.userInfo)
		},
		data() {
			return {
				dialogVisible: false,
				username: 'root',
				todos: [{
						key: 1,
						name: '娱乐清单',
						className: 'cuIcon-game'
					},
					{
						key: 2,
						name: '兴趣清单',
						className: 'cuIcon-creative'
					},
					{
						key: 3,
						name: '成就清单',
						className: 'cuIcon-selection'
					},
					{
						key: 4,
						name: '营养清单',
						className: 'cuIcon-emoji'
					}
				],
				menus: [{
						name: '时光日历',
						className: 'cuIcon-calendar',
						key: 7,
					},
					{
						name: '意见反馈',
						className: 'cuIcon-message',
						key: 5,
					},
					{
						name: '关于我们',
						className: 'cuIcon-group',
						key: 6,
					}
				]
			};
		},
		methods: {
			exit() {
				console.log('exit')
				this.dialogVisible = true
			},
			handleMenuClick(key) {
				console.log(key)
				if (key === 7) {
					uni.navigateTo({
						url: '/pages/my/myCalendar'
					})
				} else if (key === 6) {
					uni.navigateTo({
						url: '/pages/my/aboutUs'
					})
				} else if (key === 5) {
					uni.navigateTo({
						url: '/pages/my/advice'
					})
				}
			},
			handleTodoClick(key) {
				console.log(key)
				if (key === 1) {
					uni.navigateTo({
						url: '/pages/todo/entertainment'
					})
				} else if (key === 2) {
					uni.navigateTo({
						url: '/pages/todo/hobby'
					})
				} else if (key === 3) {
					uni.navigateTo({
						url: '/pages/todo/achievement'
					})
				} else if (key === 4) {
					uni.navigateTo({
						url: '/pages/todo/nutrition'
					})
					this.dialogVisible = false
				}
			},
			handleCancel() {
				this.dialogVisible = false
			},
			handleSure() {
				uni.navigateTo({
					url: '/pages/login/index'
				})
				this.dialogVisible = false
			}
		},
		computed: {
			timeStr() {
				const time = new Date().getHours()
				console.log(this.userInfo)
				console.log(time)
				if (time > 6 && time < 12) {
					return '早上'
				} else if (time >= 12 && time < 14) {
					return '中午'
				} else if (time >=14 && time < 19) {
					return '下午'
				} else {
					return '晚上'
				}
			},
			...mapState(['userInfo'])
		}
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.profily,
	.profily_header {
		border-radius: 8px;
	}

	.center {
		height: 100%;

		&_top {
			height: 18%;
			background-size: cover;
			.mask {
				background: rgba(0, 0, 0, .7);
				height: 100%;
			}
		}

		&_box_bg {
			background: rgba($color: #FEFEFE, $alpha: 0.7);;
			position: relative;
			.profily {
				position: absolute;
				width: 90%;
				margin: 0 auto;
				top: -100upx;
				left: 5%;
				background: rgba($color: #FEFEFE, $alpha: 0.7);
				padding: 35upx;
				box-sizing: border-box;
				box-shadow: 0px 2px 5px #EDEDED;
			}
		}
	}

	.base {
		display: flex;
		align-items: center;
		border-bottom: 2px solid #F6F6F6;
		padding-bottom: 35upx;
		position: relative;
		.profily_header {
			height: 120upx;
			width: 120upx;
			background-image: url('../../static/icons/header.jpg');
			background-size: 100%;
		}
		text {
			margin-top: 25px;
			margin-left: 20px;
			font-size: 30upx;
		}
		image{
			position: absolute;
			height: 40upx;
			width: 40upx;
			right: 0px;
			top:0px;
		}
	}
	.order_todos {
		display: flex;
		justify-content: space-between;
		margin-top: 35upx;
		.todos {
			width: 140upx;
			font-size: 24upx;
			text-align: center;
			letter-spacing: .5px;
			display: flex;
			flex-direction: column;
			.todos_icons {
				font-size: 70rpx;
				color: $theme-color;
			}
		}
	}
	.baiban {
		background: rgba($color: #FEFEFE, $alpha: 0.7);
		height: 300upx;
	}
	.center_menu {
		width: 100%;
		display: inline-block;
		.menu_item {
			font-size: 28upx;
			letter-spacing: 1px;
			padding: 14px 5%;
			background: rgba($color: #FEFEFE, $alpha: 0.7);
			overflow: hidden;
			box-sizing: border-box;
			display: flex;
			align-items: center;
			position: relative;
			border-bottom: 1px solid #EFEFEF;
			.menu_icons {
				font-size: 40rpx;
				color: $theme-color;
			}
			&:hover {
				background: rgba($color: #FEFEFE, $alpha: 0.7) !important;
			}

			&::after {
				content: '';
				width: 30upx;
				height: 30upx;
				position: absolute;
				right: 5%;
				background: url('../../static/icons/right.png') no-repeat;
				background-size: 100%;
			}

			text:nth-of-type(1) {
				margin-left: 10px;
			}

			image {
				width: 40upx;
				height: 40upx;
			}

			&:nth-of-type(4) {
				margin-top: 10px;
			}
		}
	}
	.setting-icon {
		font-size: 200rpx;
		color: $theme-color;
		position: absolute;
		top: 10px;
		right: 0;
	}
</style>
